package pers.yurwisher.rubick.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import pers.yurwisher.rubick.common.utils.ObjectHelper;

import javax.servlet.Servlet;
import java.util.List;

/**
 * @author yq
 * @date 2018/04/18 14:05
 * @description web上下文配置
 * @since V1.0.0
 */
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass({Servlet.class, DispatcherServlet.class, WebMvcConfigurationSupport.class})
@Slf4j
public class CustomWebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        log.info("auto add FastJsonHttpMessageConverter");
        converters.add(ObjectHelper.getDefaultFastJsonHttpMessageConverter());
    }

}
